package org.example.studyonline.pojo.VO;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Arrays;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserInfoVO {
    private Integer userID;
    private String name;
    private String email;
    private Integer isFrozen;
    private String isVIP;
    @JsonIgnore
    private String roles;  // 初始为String类型

    // 添加一个方法将roles字符串转换为List<Integer>
    @JsonProperty("roles")
    public List<Integer> getRoleList() {
        if (roles == null || roles.isEmpty()) {
            return new java.util.ArrayList<>();
        }
        return Arrays.stream(roles.split(","))
                .map(Integer::parseInt)
                .collect(Collectors.toList());
    }
}

